﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// AC总分排行榜
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class rankList : onlineJudge.rankList<rankList>
    {
        /// <summary>
        /// AC总分排行榜缓存数据
        /// </summary>
        private struct cacheValue
        {
            /// <summary>
            /// 排行列表
            /// </summary>
            public int[] UserIds;
            /// <summary>
            /// 总数量
            /// </summary>
            public int Count;
        }
        /// <summary>
        /// AC总分排行榜客户端缓存
        /// </summary>
        private static readonly fastCSharp.sql.logCache<cacheValue> cache = new fastCSharp.sql.logCache<cacheValue>(diantou.dataAccess.tcpCall.contest.onRankLog);
        /// <summary>
        /// 分页连接
        /// </summary>
        private static readonly string path = diantou.dataModel.path.pub.Default.ContestRankPath + "?";
        /// <summary>
        /// 获取排行列表
        /// </summary>
        protected override diantou.dataAccess.user[] users
        {
            get
            {
                fastCSharp.sql.logCache<cacheValue>.value cacheValue = pageInfo.Page <= 1 ? cache.Value : default(fastCSharp.sql.logCache<cacheValue>.value);
                if (cacheValue.Value.UserIds == null)
                {
                    cacheValue.Value.UserIds = diantou.dataAccess.tcpCall.contest.getRankUserIds(20, pageInfo.Page, out cacheValue.Value.Count);
                    cache.Set(ref cacheValue);
                }
                pageInfo.Set(20, cacheValue.Value.Count);
                return diantou.dataAccess.clientCache.User.Get(cacheValue.Value.UserIds);
            }
        }
        /// <summary>
        /// 当前用户排行
        /// </summary>
        protected override int currentUserRank { get { return currentUser.ContestRank; } }
        /// <summary>
        /// 分页连接
        /// </summary>
        protected override string pagePath { get { return path; } }
    }
}
